//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
/*
;***
;ullshr.asm - long shift right
;
;       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
;
;Purpose:
;   define unsigned long shift right routine
;       __aullshr
;******************************************************************************

;***
;ullshr - long shift right
;
;Purpose:
;   Does a unsigned Long Shift Right
;   Shifts a long right any number of bits.
;
;Entry:
;   EDX:EAX - long value to be shifted
;   CL    - number of bits to shift by
;
;Exit:
;   EDX:EAX - shifted value
;
;Uses:
;   CL is destroyed.
;
;Exceptions:
;
;*****************************************************************************/

//==========================================================================
// Copyright (c) 2000-2004,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
//
// The original program was copied from Microsoft Visual Studio 6.0
// Enterprise Edition.  This file is adapted for Zee operating system.
//==========================================================================

#include <elatypes.h>

__declspec(naked) void __cdecl _aullshr(void)
{
    __asm {
;
; Handle shifts of 64 bits or more (if shifting 64 bits or more, the result
; depends only on the high order bit of edx).
;
    cmp cl,64
    jae short RETZERO

;
; Handle shifts of between 0 and 31 bits
;
    cmp cl, 32
    jae short MORE32
    shrd    eax,edx,cl
    shr edx,cl
    ret

;
; Handle shifts of between 32 and 63 bits
;
MORE32:
    mov eax,edx
    xor edx,edx
    and cl,31
    shr eax,cl
    ret

;
; return 0 in edx:eax
;
RETZERO:
    xor eax,eax
    xor edx,edx
    ret
    }
}
